Skip to content

Conversation

@BrianLusina
Copy link
Owner

@BrianLusina BrianLusina commented Jan 26, 2026

Describe your change:

Minimum number of pushes to type word on a phone keypad using greedy algorithm and an alternative using a max heap

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Summary by CodeRabbit

  • New Features

    • Added two algorithmic solutions for the "minimum pushes to type a word" problem.
  • Documentation

    • Added comprehensive problem documentation with descriptions, examples, constraints, and step-by-step solution explanations.
    • Updated directory organization: moved/added entries to better reflect algorithm categories (Dynamic Programming and Greedy).
  • Tests

    • Added tests verifying the new algorithm implementations.

✏️ Tip: You can customize this high-level summary in your review settings.

@BrianLusina BrianLusina self-assigned this Jan 26, 2026
@BrianLusina BrianLusina added enhancement Algorithm Algorithm Problem Datastructures Datastructures Documentation Documentation Updates Strings Greedy Greedy Algorithm Heap labels Jan 26, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds a new Greedy algorithm "Minimum Number of Pushes to Type Word" with two implementations (sorting-based and heap-based), tests, README, and a DIRECTORY.md update that also adds an entry for Longest Increasing Subsequence under Dynamic Programming and removes a duplicate LIS entry under Puzzles > Arrays.

Changes

Cohort / File(s) Summary
Directory & Index
DIRECTORY.md
Added Greedy entry for "Minimum Number Of Pushes" and added Dynamic Programming entry for "Longest Increasing Subsequence"; removed duplicate LIS entry under Puzzles > Arrays.
Documentation
algorithms/greedy/minimum_number_of_pushes/README.md
New problem README with statement, constraints, examples, two solution approaches (greedy sorting and heap), complexity notes, and illustrative diagrams.
Implementation
algorithms/greedy/minimum_number_of_pushes/__init__.py
Added two public functions: minimum_pushes_greedy_with_sorting(word: str) -> int and minimum_pushes_heap(word: str) -> int, both compute total key presses using letter frequencies and groups of 8 per key.
Tests
algorithms/greedy/minimum_number_of_pushes/test_minimum_number_of_pushes.py
New parameterized tests validating both implementations across multiple (word, expected_pushes) cases, including a main guard for direct execution.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through keys both near and far,
Counting letters, grouping by eight, what a star!
Sorting and heaping, I choose which to press,
Fewer pushes, less stress—what a success! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main addition: a new greedy algorithm solution for computing the minimum number of pushes to type a word on a phone keypad.
Description check ✅ Passed The description follows the repository template with clear problem statement, proper checklist completion, and indicates comprehensive compliance with contribution guidelines including type hints, doctests, and algorithm documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@algorithms/greedy/minimum_number_of_pushes/__init__.py`:
- Around line 5-14: In the function minimum_pushes_greedy_with_sorting, fix the
typos in the comments: change "storees" to "stores" in the comment describing
the frequency vector and change "throuch" to "through" in the loop comment; no
code logic changes needed—just update the comment text around the frequency =
[0] * 26 line and the for char in word: loop comment to correct the spelling.

In `@algorithms/greedy/minimum_number_of_pushes/README.md`:
- Around line 112-116: Fix the minor markdown formatting on the README by
replacing the double space after the blockquote marker on the affected line
(change ">  " to "> ") so the quoted paragraph renders consistently; locate the
quoted paragraph starting with "the number of pushes required to obtain a single
instance..." in algorithms/greedy/minimum_number_of_pushes/README.md and
normalize the blockquote punctuation.
🧹 Nitpick comments (1)
algorithms/greedy/minimum_number_of_pushes/__init__.py (1)

16-19: Clarify complexity comment for sorting.

The comment says "O(n log(n)) operation" and "space complexity of O(n)", but the array being sorted is always size 26 (constant), not n. This is effectively O(1) time and O(1) auxiliary space. Consider updating the comment for accuracy:

📝 Suggested clarification
-    # Sort the frequencies in descending order to prioritize letters with higher counts
-    # O(n log(n)) operation to handle sorting, with a space complexity of O(n) as Python uses in-memory space to handle
-    # the sorting using timsort
+    # Sort the frequencies in descending order to prioritize letters with higher counts
+    # O(26 log 26) = O(1) operation since the array size is constant (26 letters)
     frequency.sort(reverse=True)

BrianLusina and others added 2 commits January 26, 2026 09:35
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@BrianLusina BrianLusina merged commit abfe9cb into main Jan 26, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Algorithm Algorithm Problem Datastructures Datastructures Documentation Documentation Updates enhancement Greedy Greedy Algorithm Heap Strings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants